/****************************************************************************
 *   <SPG2 - Secure Password Generator>
 *   Copyright (C) 2010  <Robert Carr>
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *   @author Robert Carr (etftw)
 *   @version 2.5.4
 *   
 ***************************************************************************/

package spg2;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class SetupWizard extends JDialog implements ActionListener 
{
	private static final long serialVersionUID = -8754868735154095679L;
	private static boolean instantiated;
	private ImagePanel imgLogo;

	public static void setInstantiated(boolean instantiated) 
	{
		SetupWizard.instantiated = instantiated;
	}

	public static boolean isInstantiated() 
	{
		return instantiated;
	}
	
	public SetupWizard(JFrame parent, String title) throws Exception
	{
		super(parent, title, true);
		if(SetupWizard.isInstantiated())
		{
			throw new Exception("Class already instantiated");
		}
		else
		{
			setupUI();
			SetupWizard.setInstantiated(true);
		}
	}
	
	private void setupUI()
	{
		// Set the dialog location and size
		int x = ((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2) - 300;
        int y = ((int)Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2) - 175;
        setLocation(x, y);
		setSize(600, 350);
		setLayout(null);
		setResizable(false);
        
		JPanel stepOne = setupStepOne();
		stepOne.setVisible(true);
		
		add(stepOne);
		
		// Display the dialog
		setVisible(true);
	}
	
	private JPanel setupStepOne()
	{
		JPanel stepOne = new JPanel();
		stepOne.setLayout(null);
		
		// Initialize the logo
        imgLogo = new ImagePanel(new ImageIcon(SPG2.class.getResource("logo.png")).getImage());
        imgLogo.setLocation((getWidth() / 2) - 190, 10);
        imgLogo.setVisible(true);
		
        // Initialise the caption
        JLabel caption = new JLabel("Authentication Method");
        caption.setLocation(imgLogo.getLocation().x + 40, (imgLogo.getLocation().y + 100) + 5);
        caption.setSize(500, 30);
        caption.setVisible(true);
        
        // Initialise the radio buttons
        JRadioButton highSecurity, mediumSecurity, lowSecurity;
        highSecurity = new JRadioButton("Passphrase & Key File (Recommended)");
        highSecurity.setSelected(true);
        highSecurity.setLocation(caption.getLocation().x, (caption.getLocation().y + 30));
        highSecurity.setSize(500, 20);
        highSecurity.setVisible(true);
        
        mediumSecurity = new JRadioButton("Key File");
        mediumSecurity.setSelected(true);
        mediumSecurity.setLocation(highSecurity.getLocation().x, (highSecurity.getLocation().y + 20));
        mediumSecurity.setSize(500, 20);
        mediumSecurity.setVisible(true);
        
        lowSecurity = new JRadioButton("Passphrase");
        lowSecurity.setSelected(true);
        lowSecurity.setLocation(mediumSecurity.getLocation().x, (mediumSecurity.getLocation().y + 20));
        lowSecurity.setSize(500, 20);
        lowSecurity.setVisible(true);
        
        // Initialise the button group
        ButtonGroup bg = new ButtonGroup();
        bg.add(highSecurity);
        bg.add(mediumSecurity);
        bg.add(lowSecurity);
        
        // Initialise the previous button
        JButton previous = new JButton("Previous");
        previous.setLocation(lowSecurity.getLocation().x, (lowSecurity.getLocation().y + 30));
        previous.setSize(90, 20);
        previous.setVisible(true);
        
        // Initialise the next button
        JButton next = new JButton("Next");
        next.setLocation((previous.getLocation().x + 110), previous.getLocation().y);
        next.setSize(70, 20);
        next.setVisible(true);
        
        // Add the components
        stepOne.add(imgLogo);
        stepOne.add(caption);
        stepOne.add(highSecurity);
        stepOne.add(mediumSecurity);
        stepOne.add(lowSecurity);
        stepOne.add(previous);
        stepOne.add(next);
        stepOne.setSize(600, 350);
        stepOne.setLocation(0, 0);
        
        return stepOne;
	}

	private JPanel setupStepTwo()
	{
		JPanel stepTwo = new JPanel();
		stepTwo.setLayout(null);
		
		// Initialize the logo
        imgLogo = new ImagePanel(new ImageIcon(SPG2.class.getResource("logo.png")).getImage());
        imgLogo.setLocation((getWidth() / 2) - 190, 10);
        imgLogo.setVisible(true);
		
        // Initialise the caption
        JLabel caption = new JLabel("Authentication Method");
        caption.setLocation(imgLogo.getLocation().x + 40, (imgLogo.getLocation().y + 100) + 5);
        caption.setSize(500, 30);
        caption.setVisible(true);
        
        // Initialise the radio buttons
        JRadioButton highSecurity, mediumSecurity, lowSecurity;
        highSecurity = new JRadioButton("Passphrase & Key File (Recommended)");
        highSecurity.setSelected(true);
        highSecurity.setLocation(caption.getLocation().x, (caption.getLocation().y + 30));
        highSecurity.setSize(500, 20);
        highSecurity.setVisible(true);
        
        mediumSecurity = new JRadioButton("Key File");
        mediumSecurity.setSelected(true);
        mediumSecurity.setLocation(highSecurity.getLocation().x, (highSecurity.getLocation().y + 20));
        mediumSecurity.setSize(500, 20);
        mediumSecurity.setVisible(true);
        
        lowSecurity = new JRadioButton("Passphrase");
        lowSecurity.setSelected(true);
        lowSecurity.setLocation(mediumSecurity.getLocation().x, (mediumSecurity.getLocation().y + 20));
        lowSecurity.setSize(500, 20);
        lowSecurity.setVisible(true);
        
        // Initialise the button group
        ButtonGroup bg = new ButtonGroup();
        bg.add(highSecurity);
        bg.add(mediumSecurity);
        bg.add(lowSecurity);
        
        // Initialise the previous button
        JButton previous = new JButton("Previous");
        previous.setLocation(lowSecurity.getLocation().x, (lowSecurity.getLocation().y + 30));
        previous.setSize(90, 20);
        previous.setVisible(true);
        
        // Initialise the next button
        JButton next = new JButton("Next");
        next.setLocation((previous.getLocation().x + 110), previous.getLocation().y);
        next.setSize(70, 20);
        next.setVisible(true);
        
        // Add the components
        stepTwo.add(imgLogo);
        stepTwo.add(caption);
        stepTwo.add(highSecurity);
        stepTwo.add(mediumSecurity);
        stepTwo.add(lowSecurity);
        stepTwo.add(previous);
        stepTwo.add(next);
        stepTwo.setSize(600, 350);
        stepTwo.setLocation(0, 0);
        
        return stepTwo;
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) 
	{
	}
}